//
//  LYPersonDetailView.m
//  SZBank
//
//  Created by LuoYao on 16/7/9.
//  Copyright © 2016年 LuoYao. All rights reserved.
//

#import "LYPersonDetailView.h"

@interface LYPersonDetailView ()
{
    NSDictionary *dic;
}
@end
@implementation LYPersonDetailView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self initDataSource];
        
        
        //背景图片
        UIImageView *backImage = [[UIImageView alloc] initWithFrame:self.frame];
        backImage.image = [LocalDataManager getImageWithSourceOfPath:@"个人信息"];
        
        [self addSubview:backImage];
        
        //关闭按钮
        UIButton *cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(KWIDTH * 0.85, KHEIGHT * 0.13, 60, 60)];
        [cancelBtn setImage:[LocalDataManager getImageWithSourceOfPath:@"金融资讯_详情关闭"] forState:UIControlStateNormal];
        [cancelBtn addTarget:self action:@selector(action_BtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:cancelBtn];
        
        
        //头像
        self.headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(KWIDTH * 0.15, KHEIGHT * 0.3, KWIDTH * 0.2, KWIDTH * 0.2)];
        
        self.headerImageView.clipsToBounds = YES;
        self.headerImageView.layer.cornerRadius = KWIDTH * 0.1;
        [self getHeaderImage];
        
        [self addSubview:self.headerImageView];
        
        //头像下文字
        UIImageView *headerLineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(KWIDTH * 0.15, KHEIGHT * 0.65, KWIDTH * 0.2, KWIDTH * 0.07)];
        headerLineImageView.image = [LocalDataManager getImageWithSourceOfPath:@"个人信息_logo"];
        
        [self addSubview:headerLineImageView];
        
        
        //银行名称
        UILabel *bankName = [[UILabel alloc] initWithFrame:CGRectMake(KWIDTH * 0.45, KHEIGHT * 0.32, KWIDTH * 0.1, KHEIGHT * 0.05)];
        bankName.text = dic[@"ORGNISITION"];
        bankName.font = [UIFont systemFontOfSize:FONT_SIZE];
        bankName.textColor = [UIColor whiteColor];
        
        [self addSubview:bankName];
        
        
        
        //个人信息
        for (int i = 0; i < 6; i ++) {
            UILabel *lb = [[UILabel alloc] initWithFrame:CGRectMake(KWIDTH * 0.55, KHEIGHT * 0.375 + i * KHEIGHT * 0.055, KWIDTH * 0.2, KHEIGHT * 0.05)];
            lb.text = dic[@"list"][i];
            lb.font = [UIFont systemFontOfSize:FONT_SIZE];
            lb.textColor = [UIColor whiteColor];
            
            [self addSubview:lb];
        }
        
        
        
        
    }
    return self;
}

/**< 初始化数据源 */
- (void)initDataSource{
    if (![PersonInfoSingle defaultPersonInfo].loginPersonInfo) {
        return;
    }
    
    NSDictionary *dc = [PersonInfoSingle defaultPersonInfo].loginPersonInfo;
    //对数据存数据
    NSArray *dataSource = @[dc[@"REALNAME"],dc[@"SEX"],dc[@"TELNUMBER"],dc[@"EMAIL"],dc[@"WORKID"],dc[@"POSITION"]];
    
    dic = @{@"HEADURL":dc[@"HEADURL"],@"REALNAME":dc[@"REALNAME"],@"ORGNISITION":dc[@"ORGNISITION"],@"list":dataSource};
}



//获取图片
- (void)getHeaderImage{
    //从plist文件中获取头像
    NSData *imageData = [LocalDataManager getImageDataWithPlist];
    UIImage *image = [UIImage imageWithData:imageData];
    self.headerImageView.image = image;
}

#pragma mark - 点击事件
- (void)action_BtnClick{
    [self removeFromSuperview];
}
@end
